<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:py="http://genshi.edgewall.org/">
  <xi:include href="discussion-macros.html"/>
  <xi:include href="layout.html"/>
  <head>
    <title>Forum List</title>

<script type="text/javascript">
function blurSearchBar()
{
    if (document.fullsearch.q.value == "Search in Forum") {
            document.fullsearch.q.style.fontStyle="italic";
    }
    if (document.fullsearch.q.value == "") {
        document.fullsearch.q.value = "Search in Forum";
        document.fullsearch.q.style.fontStyle="italic";
    }

}
function focusSearchBar() {

    document.fullsearch.q.style.fontStyle="normal";
    if (document.fullsearch.q.value == "Search in Forum") {
            document.fullsearch.q.value = '';
    }
}

$(document).ready(function() {
    $("#sorting option[name='${discussion.order}']").attr('selected', 'selected');
});

</script>

  </head>

  <?python
    from trac.util.datefmt import format_datetime, pretty_timedelta
    from multiproject.core.configuration import conf
  ?>

  <py:def function="display_group(group, forums)">




<!-- forum, moderator, replies, views, topics, last post -->

    <h2 class="report-result title">Forum index</h2>
    <hr class="prelisting" />
    <table class="listing">
      <thead>
        <tr py:if="group and group.id != 0">
          <th class="group" colspan="10">
            <div class="name">${group.name}</div>
            <div class="description">${group.description}</div>
          </th>
        </tr>
        <tr id="lower">
          ${sortable_th_nc(discussion.order, discussion.desc, 'subject', 'Forum', href.discussion())}
          ${sortable_th_nc(discussion.order, discussion.desc, 'moderators', 'Moderator', href.discussion())}
          ${sortable_th_nc(discussion.order, discussion.desc, 'replies', 'Replies', href.discussion())}
          ${sortable_th_nc(discussion.order, discussion.desc, 'topics', 'Topics', href.discussion())}
          ${sortable_th_nc(discussion.order, discussion.desc, 'viewcount', 'Views', href.discussion())}
          ${sortable_th_nc(discussion.order, discussion.desc, 'lastpost', 'Last Post', href.discussion())}

        </tr>
      </thead>
      <tbody>
        <py:for each="line, forum in enumerate(forums)">
          <tr py:if="forum.forum_group == group.id" class="${line % 2 and 'forumlistrow_even' or 'forumlistrow_odd'}">
            <td class="forumlist_title">
              <div class="subject">
                <a href="${href.discussion('forum', forum.id)}">
                  <span>${forum.subject or '&nbsp;'}</span>
                </a>
              </div>
              <div class="founded">
                <span>
                  ${fromtimestamp(forum.time).strftime("%a %d %b, %Y %H:%M:%S")}
                </span>
                <span py:if="forum.new_replies > 0 or forum.new_topics > 0" class="topicnewtag">NEW</span>
              </div>

            </td>

            <td class="forumlist_moderators">
              <div class="moderators">
                <py:choose test="len(forum.moderators)">
                  <py:when test="0">
                    <span>&nbsp;</span>
                  </py:when>                
                  <py:otherwise>
                    <py:for each="moderator in forum.moderators">
                      ${format_author(moderator)}<br/>
                    </py:for>
                  </py:otherwise>
                </py:choose>
              </div>
            </td>

            <td class="forumlist_replies">
              <div class="replies">
                <span>${forum.replies or '0'}</span>
              </div>
            </td>

            <td class="forumlist_topics">
              <div class="topics">
                <span>${forum.topics or '0'}</span>
              </div>
            </td>

            <td class="forumlist_view">
              <div class="views">
                <span>${forum.viewcount or '0'}</span>
              </div>
            </td>


            <td class="forumlist_lastpost">
              <div class="lastposter">
                  <py:if test="forum.lastposter"><a href="${conf.url_home_path}/user/${forum.lastposter}">${format_author(forum.lastposter)}</a></py:if>
                  <py:if test="not forum.lastposter">no posts</py:if>
              </div>
              <div class="lastmodified">
                    ${forum.lastposttime and fromtimestamp(forum.lastposttime).strftime("%a %d %b, %Y %H:%M:%S") or ''}
              </div>
            </td>

          </tr>
        </py:for>
      </tbody>
    </table>
    <hr class="postlisting" />
  </py:def>

  <body>
    <xi:include href="discussion-header.html"/>

    <div id="content" class="discussion" style="position:static;">
      <div id="${discussion.mode}" class="${discussion.mode}">
        <h1 class="subpage_title">Forum List</h1>
        <div py:if="'DISCUSSION_ADMIN' in perm" class="buttons">
           <form method="post" action="${href.discussion()}">
            <div>
                <span class="secondaryButton" id="createforum">
                    <input type="submit" name="newforum" value="Create New Forum" />
                </span> 
              <input type="hidden" name="discussion_action" value="add"/>
            </div>
          </form>
        </div>

        <div id="searchbar">
            <form method="get" action="${href.discussion()}" id="showsettings" name="showsettings">
               <div id="sortingbox" name="order">
                    <span id="sorttxt">Sort by:</span>
                    <select class="selectMenu" id="sorting" name="order">
                       <option name="subject" value="subject">Forum name</option>
                       <option name="lastpost" value="lastpost">Last Post</option>
                       <option name="topics" value="topics">Topics</option>
                       <option name="replies" value="replies">Replies</option>
                       <option name="viewcount" value="viewcount">Views</option>
                   </select>
                   <button type="submit" id="go">${_('Go')}</button>
                </div>
            </form>
   
            <form method="get" action="${req.base_path}/search" id="fullsearch" name="fullsearch">
              <div id="searchbox">
                <input type="text" value="Search in Forum" name="q" id="q" onclick="focusSearchBar()" onblur="blurSearchBar()"/>
                <input type="hidden" value="1" name="noquickjump" />
                <input type="hidden" checked="checked" name="discussion" id="discussion" value="on" />
                <button type="submit" value="" id="submit" />
              </div>
            </form>

    </div>


        <py:choose>
          <py:for py:when="len(discussion.forums)" each="group in discussion.groups">
            <py:if test="group.forums">
              ${display_group(group, discussion.forums)}
            </py:if>
          </py:for>
          <py:otherwise>
            <div class="greyBgContainer" style="margin-top:25px;width:250px;clear:both;">
              <div class="greyBgContent">
                <span style="font-weight: bold;">There are no forums created.</span>
                <div py:if="'DISCUSSION_ADMIN' in perm">
                    <br/>
                    You can create them in <a href="${req.base_path}/admin/discussion/forum">Forum admin panel</a>.
                </div>
              </div>
            </div>
          </py:otherwise>
        </py:choose>


      </div>
    </div>

    <xi:include href="discussion-footer.html"/>
  </body>
</html>
